import Vue from 'vue';
import Vuex from 'vuex';
import createPersistedState from 'vuex-persistedstate';

Vue.use(Vuex);

const store = new Vuex.Store({
  plugins: [createPersistedState()],
  state: {
    randedNumbers: [],
  },
  getters: {
    randedNumbers: (state) => state.randedNumbers,
  },
  mutations: {
    SET_RANDED_NUMBER(state, number) {
      state.randedNumbers.push(number);
    },
    RESET_RANDED_NUMBER(state) {
      state.randedNumbers = [];
    },
  },
  actions: {
    addRandedNumber({ commit }, number) {
      commit('SET_RANDED_NUMBER', number);
    },
    resetRandedNumber({ commit }) {
      commit('RESET_RANDED_NUMBER');
    },
  },
});

export default store;
